package com.xiaokaceng.openci.domain;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.openkoala.koala.commons.domain.KoalaAbstractEntity;

@Entity
@Table(name = "project_developers")
public class ProjectDeveloper extends KoalaAbstractEntity {

	private static final long serialVersionUID = -5833807367997029745L;

	private Developer developer;

	private Project project;

	private boolean isNotice = false;

	private boolean isSyncCas = false;

	private String noticeFailureCause;

	private String syncCasFailureCause;

	ProjectDeveloper() {
	}

	@Override
	public String[] businessKeys() {
		return new String[0];
	}

	public ProjectDeveloper(Developer developer, Project project) {
		this.developer = developer;
		this.project = project;
	}

	@OneToOne
	@JoinColumn(name = "developer_id")
	public Developer getDeveloper() {
		return developer;
	}

	@Column(name = "is_notice")
	public boolean isNotice() {
		return isNotice;
	}

	public void setNotice(boolean isNotice) {
		this.isNotice = isNotice;
	}

	@Column(name = "is_sync_cas")
	public boolean isSyncCas() {
		return isSyncCas;
	}

	public void setSyncCas(boolean isSyncCas) {
		this.isSyncCas = isSyncCas;
	}

	@Lob
	@Column(name = "notice_failure_cause")
	public String getNoticeFailureCause() {
		return noticeFailureCause;
	}

	public void setNoticeFailureCause(String noticeFailureCause) {
		this.noticeFailureCause = noticeFailureCause;
	}

	@Lob
	@Column(name = "sync_cas_failure_cause")
	public String getSyncCasFailureCause() {
		return syncCasFailureCause;
	}

	public void setSyncCasFailureCause(String syncCasFailureCause) {
		this.syncCasFailureCause = syncCasFailureCause;
	}

	@Override
	public boolean equals(Object other) {
		if (this == other) {
			return true;
		}
		if (!(other instanceof ProjectDeveloper)) {
			return false;
		}
		ProjectDeveloper that = (ProjectDeveloper) other;
		return new EqualsBuilder().append(getDeveloper(), that.getDeveloper()).append(getProject(), that.getProject()).isEquals();

	}

	@Override
	public int hashCode() {
		return new HashCodeBuilder().append(getDeveloper()).append(getProject()).hashCode();
	}

	@Override
	public String toString() {
		return getDeveloper().toString();
	}

	@ManyToOne
	@JoinColumn(name = "project_id")
	protected Project getProject() {
		return project;
	}

	public void setDeveloper(Developer developer) {
		this.developer = developer;
	}

	public void setProject(Project project) {
		this.project = project;
	}

}
